package com.example.lesson2.Controller;

import com.example.lesson2.config.MailConstants;
import com.example.lesson2.config.MyApp;
import com.example.lesson2.config.MyApp1;
import com.example.lesson2.config.RabbitConfig;
import jakarta.annotation.Resource;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@Controller
public class helloController {

    @Autowired
    private Date date;
    @Value("${myapp.host}")
    private String hostname;
    @Resource
    private MyApp myApp;
    @Resource
    private MyApp1 myApp1;
    @Resource
    private RabbitTemplate rabbitTemplate;

    @RequestMapping("hello")
    public String hello(String name) {
//        Map<Object, Object> map = new HashMap<>();
//        map.put("name",name);
//        map.put("myApp -class",myApp.getClass());
//        map.put("myApp1 -class",myApp1.getClass());
//        map.forEach((key, value) -> System.out.println("Key: " + key + ", Value: " + value));
        Message message = new Message("测试消息".getBytes());
        rabbitTemplate.convertAndSend(MailConstants.MAIL_EXCHANGE_NAME, MailConstants.MAIL_ROUTING_KEY_NAME, message, new CorrelationData("1"));
        return "";
    }
}
